﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MillerApp.CommonLib.DataAccess;

namespace MillerApp.CommonLib.Utility
{
    /// <summary>
    /// 枚举相关帮助类
    /// </summary>
    public class EnumHelper
    {
        /// <summary>
        /// 根据字符串转换为枚举值
        /// </summary>
        /// <typeparam name="T">枚举类型</typeparam>
        /// <param name="enumString">字符串</param>
        /// <returns>枚举值</returns>
        public static T Convert<T>(string enumString)
        {
            T t=(T)Enum.Parse(typeof(T), enumString,true);
            return t;
        }
        /// <summary>
        /// 根据枚举代表的数字获取枚举值
        /// </summary>
        /// <typeparam name="T">枚举类型</typeparam>
        /// <param name="i">数字</param>
        /// <returns></returns>
        public static T Convert<T>(int i)
        {
            T t = (T)Enum.Parse(typeof(T), i.ToString(), true);
            return t;
        }
        /// <summary>
        /// 获取到枚举的Name列表
        /// </summary>
        /// <param name="enumType">枚举类型</param>
        /// <returns>枚举名称列表</returns>
        public static List<string> GetEnumNames<T>()
        {
            List<string> list=Enum.GetNames(typeof(T)).ToList<string>();
            return list;
        }
        
    }
}
